package com.study.jdbc.junit;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import org.junit.Test;

import com.study.jdbc.utils.DBUtil;

/**
* @Name: DBUtilTest
* @Description: DBUtil工具测试类
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-2-16 下午7:26:42 
* @Version: V1.0
 */
public class DBUtilTest {
	
	@Test
	public void test() {
		Connection con = null ;
		Statement s = null ;
		ResultSet rs = null ;
		try {
			//获取数据库连接对象
			con = DBUtil.getConnection() ;
			//创建sql语句执行对象
			s = con.createStatement() ;
			//执行sql语句，获取结果集对象，遍历结果集
			String sql = "select id, name, gender, birthday, cellphone, email, preference, type, description from t_customer ; " ;
			rs = s.executeQuery(sql) ;
			while(rs.next()) {
				System.out.println("===================================");
				System.out.println(rs.getString("id"));
				System.out.println(rs.getString("name"));
				System.out.println(rs.getString("gender"));
				System.out.println(rs.getDate("birthday"));
				System.out.println(rs.getString("cellphone"));
				System.out.println(rs.getString("preference"));
				System.out.println(rs.getString("type"));
				System.out.println(rs.getString("description"));
			}
		} catch (Exception e) {
			e.printStackTrace() ;
		} finally {
			//释放资源
			DBUtil.close(con, s, rs) ;
		}
	}

}
